<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="cn.cslg.news.entity.Member"%>
<%@page import="java.util.ArrayList"%>
<jsp:include page="header.jsp" />
<script>
	$(document).ready(function() {
		$("#btnAdd").click(function() {
			document.location = '${ContextPath}admin/adduser.jsp';
		});
		$(".btnBanUser").click(function() {
			var uid = $(this).attr("user-id");
			$.post("${ContextPath}admin/banuser", {
				"uid" : uid
			}, function(data) {
				alert(data);
				document.location.reload();
			});
		});
	});

	function changepass(uid) {
		document.location = '${ContextPath}admin/change_userpass.jsp?uid='
				+ uid;
	}
</script>
<div class="section" style="min-height: 80vh">
	<div class="container">
		<div class="row">
			<div class="col-md-3">
				<jsp:include page="leftmenu.jsp"/>
			</div>
			<div class="col-md-9">
				<div class="content-header">
				用户列表
				</div>
				<div style="margin-bottom: 10px">
				<input type="button" value="添加用户" id="btnAdd"
					onclick="document.location='${ContextPath}admin/adduser.jsp'" />
				</div>
				<div>
				<table class="table-responsive tlist">
					<tr>
						<td>uid</td>
						<td>用户名</td>
						<td>姓名</td>
						<td>电子邮件</td>
						<td>帐号激活</td>
						<td>帐号可用</td>
						<td>操作</td>
					</tr>
					<%
						ArrayList<Member> list = (ArrayList<Member>) request.getAttribute("USERLIST");
						for (Member u : list) {
					%>
					<tr>
						<td><%=u.getUid()%></td>
						<td><%=u.getUsername()%></td>
						<td><%=u.getTruename()%></td>
						<td><%=u.getEmail()%></td>
						<td class="user-status<%=u.getActivated()%>"></td>
						<td class="user-status<%=u.getEnabled()%>"></td>
						<td><input type="button" value="修改密码"
							onclick="changepass('<%=u.getUid()%>')" /> <%
 	if (u.getEnabled() == 1) {
 %> <input type="button" value="禁用" user-id="<%=u.getUid()%>"
							class="btnBanUser" /> <%
 	} else {
 %> <input type="button" value="启用"
							user-id="<%=u.getUid()%>" class="btnBanUser" /> <%
 	}
 %></td>
					</tr>
					<%
						}
					%>
				</table>
				</div>
			</div>
		</div>
	</div>
</div>
<jsp:include page="footer.jsp" />